package com.aaa.service.sas.impl;

import com.aaa.dao.sas.ViewTestResultSasDao;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.sas.TestResultSas;

import com.aaa.entity.sas.ViewTestResultSas;
import com.aaa.service.sas.ViewTestResultSasService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：马明钢
 * @date ：Created in 2022/9/5 20:34
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class ViewTestResultSasServiceImpl implements ViewTestResultSasService {
    @Autowired
    ViewTestResultSasDao viewTestResultSasDao;

    @Override
    public Page queryAll(PageSortEntity page, ViewTestResultSas vs) {
        PageHelper.startPage(page.getPage(), page.getLimit(), page.getOrderString());
        List<ViewTestResultSas> list = viewTestResultSasDao.queryAll(vs);
        Page page1 = (Page) list;
        return page1;
    }

    @Override
    public boolean delete(String id) {
        boolean delete = viewTestResultSasDao.delete(id);
        return delete;
    }

    @Override
    public ViewTestResultSas queryResultById(Integer id) {
        ViewTestResultSas vs = viewTestResultSasDao.queryResultById(id);
        return vs;
    }

    @Override
    public Map<String, Integer> queryAllPlanSas() {
        int normal = 0;
        int mild = 0;
        int moderate = 0;
        int severe = 0;
        List<ViewTestResultSas> viewSass = this.viewTestResultSasDao.queryAllPlanSas();
        for (ViewTestResultSas viewSas : viewSass) {
            if (viewSas.getSum() <= 50) {
                normal++;
            } else if (viewSas.getSum() >= 50 && viewSas.getSum() <= 59) {
                mild++;
            } else if (viewSas.getSum() >= 60 && viewSas.getSum() <= 69) {
                moderate++;
            } else {
                severe++;
            }
        }
        Map<String, Integer> map = new HashMap<>();
        map.put("normal", normal);
        map.put("mild", mild);
        map.put("moderate", moderate);
        map.put("severe", severe);
        return map;
    }

    /*答题结束根据分数跳转*/
    @Override
    public String selectById(Integer id) {
        ViewTestResultSas viewTestResultSas = viewTestResultSasDao.selectById(id);
        Integer sum = viewTestResultSas.getSum();
        if (sum <= 50) {
            return "sasResult/SasNormal.jsp";
        } else if (sum < 60) {
            return "sasResult/SasMild.jsp";
        } else if (sum < 70) {
            return "sasResult/SasModerate.jsp";
        } else {
            return "sasResult/SasSevere.jsp";
        }
    }

    @Override
    public Page selectAllByPerson(PageSortEntity page, TestResultSas id) {
        PageHelper.startPage(page.getPage(), page.getLimit(), page.getOrderString());
        List<TestResultSas> viewPersonResultSas = viewTestResultSasDao.selectAllByPerson(id);
        Page page1 = (Page) viewPersonResultSas;
        return page1;
    }
}
